package com.hk.rabbitmq.five;

import com.hk.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.util.Scanner;

/**
 * @author: dpb
 * @date: 2022/3/22
 */
public class EmitLog {
    private static final String EXCHANGE_NAME = "logs";

    public static void main(String[] args) throws Exception{
        Channel channel = RabbitMqUtils.getChannel();
        /**
         * 1、交换机的名称
         * 2、交换机的类型
         */
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT);

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要发送的消息：");
        while (sc.hasNext()){
            String message = sc.nextLine();
            channel.basicPublish(EXCHANGE_NAME,"123456",null,message.getBytes("UTF-8"));
            System.out.println("生产者发出消息" + message);
        }
    }
}
